<template>
	<view class="container">
		<!-- <view class="top-swiper-box">
			<uv-swiper :height="swiper_1_height" :list="swiper_list_1" keyName="src" imgMode="scaleToFill" indicator
				circular interval="4000" @click="onClickSwiper"></uv-swiper>
		</view> -->
		<!-- <view class="wjf-section">
			<view class="sevtion-left">
				<view class="border-line"></view>
				<view class="title-box">
					<text class="title-text">行业信息</text>
				</view>
			</view>
		</view> -->

		<!-- <view class="subsection-box">
			<uv-subsection :list="subsectionList" mode="subsection" :current="current" @change="change"></uv-subsection>
		</view>
		<view class="" v-if="subsectionCurrent==0">
			<text>统计信息</text>
		</view> -->
		<view class="page-content">
			<home-news-article></home-news-article>
			<home-publish-article></home-publish-article>
		</view>
		
		<!-- **********以下为测试二维码部分************* -->
		<!-- <view class="">
			<button type="default" @click="test">test</button>
		</view> -->
		<!-- <view class="">
			<button type="default" @click="testApi">testApi</button>
		</view> -->
		<!-- <view class="" style="max-width: 100vw;">
			<view style="padding: 10px;">
				<uv-qrcode ref="qrcode" size="300" value="test123668"
					:options="qrCodeOption"></uv-qrcode>
			</view>
		</view> -->
		<!-- <view class="" style="width: 300px;height: 300px;">
			<image :src="imgUrl" mode="" style="width: 100%;height: 100%;"></image>
		</view> -->

		<view class="">
			<ap126-footer></ap126-footer>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	let lang = uni.getLocale()
	import {
		uploadQRcode
	} from '/common/wjf-modules/uploadQRimgToAliOss.js'
	import adjRootFont from '/common/mixin/adj-root-font.js'
	export default {
		mixins: [adjRootFont],
		data() {
			return {
				screenWidth: 0,
				swiper_list_2: [],
				subsectionList: ['统计信息'],
				subsectionCurrent: 0,
				qrCodeOption: {
					useDynamicSize: false,
					errorCorrectLevel: 'Q',
					margin: 4,
					areaColor: "deepskyblue",
					backgroundColor: "#fff",
					// 指定二维码前景，一般可在中间放logo
					foregroundImageSrc: '/static/logo.png',
					foregroundImageBorderRadius: 5,
					// positionProbeBackgroundColor:"red",
					positionProbeForegroundColor: 'deepskyblue',
					// separatorColor:'green'
				},
				imgUrl: '',
				websiteTitle: {
					"zh-Hans": "国际汽车零部件产业发展联盟",
					"en": "International Automotive Parts Industry Development Alliance",
					"ru": "Международный альянс развития автомобильных комплектующих",
					"kk": "Халықаралық автомобиль бөлшектері индустриясын дамыту альянсы"
				}
			}
		},
		computed: {
			locaLang() {
				return uni.getLocale()
			},
			swiper_1_height() {
				let tt = 200
				if (this.screenWidth < 800) {
					tt = this.screenWidth * 0.25
				}
				return tt
			},
			systemInfo() {
				return uni.getSystemInfoSync()
			}
		},
		watch: {
			locaLang(lang) { //此处不用this
				uni.setNavigationBarTitle({
					title: this.websiteTitle[lang]
				})
			}
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.websiteTitle[this.locaLang]
			})
			this.getSwiperImgs()
		},
		methods: {
			test() {
				console.log(this.$t('国际汽车零部件产业发展联盟'));
			},
			testApi() {
				this.$refs.qrcode.toTempFilePath({
					success: (res) => {
						const base64Data = res.tempFilePath.split(',')[1];
						// 保存 Blob 为临时文件并上传
						uploadQRcode(base64Data, '', (res) => {
							// console.log(res);
						})

						// this.saveBlobAsFile(blob);
						// // 创建 URL 对象
						// const imageUrl = URL.createObjectURL(blob);
						// console.log(imageUrl);
						// this.imgUrl=imageUrl
					}
				});
			},
			// test() {
			// 	this.$refs.qrcode.toTempFilePath({
			// 		success: (res) => {
			// 			const base64Data = res.tempFilePath.split(',')[1];
			// 			const arrayBuffer = this.base64ToArrayBuffer(base64Data);
			// 			// 将 ArrayBuffer 转换为 Blob
			// 			const blob = new Blob([arrayBuffer], {
			// 				type: 'image/png'
			// 			});
			// 			// 保存 Blob 为临时文件并上传
			// 			this.saveBlobAsFile(blob);
			// 			// // 创建 URL 对象
			// 			// const imageUrl = URL.createObjectURL(blob);
			// 			// console.log(imageUrl);
			// 			// this.imgUrl=imageUrl
			// 		}
			// 	});
			// },

			change(index) {
				this.subsectionCurrent = index;
			},
			async getSwiperImgs() {
				let where =
					`(name == 'index_page_1' || name == 'index_page_2') && appID == '${this.systemInfo.appId}'`
				let {
					result
				} = await db.collection('tian-banner-category').where(where).field('name,images')
					.get();
				// console.log(result);
				// this.swiper_list_2 = result.data.filter(item=>item.name=='index_page_2')[0].images
			},
			onClickSwiper(e) {
				// console.log(e);
			},
			onSwiperChange(e) {
				// console.log(e);
			},
			// 获取屏幕宽度
			updateScreenWidth() {
				uni.getSystemInfo({
					success: (res) => {
						this.screenWidth = res.windowWidth; // 更新屏幕宽度
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.container {
		max-width: 800px;
		height: 100vh;
		/* 设置最大宽度 */
		margin: 0 auto;
		/* 居中显示 */
		// padding: 20px;
		/* 添加内边距（可选） */
		background-color: #eee;
	}

	.page-content {
		min-height: 70vh;
	}

	.top-swiper-box {
		width: 100%;
		border-bottom-left-radius: 6px;
		border-bottom-right-radius: 6px;
		overflow: hidden;
		/* 使圆角效果生效 */
		color: deepskyblue;
	}

	.wjf-section {
		margin: 10px;
		display: flex;

		.sevtion-left {
			display: flex;
			align-items: center;

			.border-line {
				width: 3px;
				height: 16px;
				background-color: dodgerblue;
				margin-right: 3px;
			}

			.title-box {
				color: #333;
				font-size: 15px;
				font-weight: 550;
			}
		}
	}

	.subsection-box {
		margin: 0 10px;
		width: 100px;
	}
</style>